package com.ea.admin.controller.superAdmin;

import com.ea.admin.permission.PermissionCode;
import com.ea.admin.pojo.Enum.Permission;
import com.ea.admin.pojo.param.superAdmin.config.EditDefaultConfParam;
import com.ea.admin.pojo.vo.superAdmin.GetDefaultConfVo;
import com.ea.admin.pojo.vo.superAdmin.GetDefaultFunctionPermissionVo;
import com.ea.admin.service.ConfigService;
import com.ea.common.log.LogAnnotation;
import com.ea.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api(tags = "超级管理-全局基础配置")
@RequestMapping("/admin/super/config")
public class SuperConfigController {
    @Resource
    ConfigService configService;

    @Transactional
    @Operation(summary = "获得全局默认配置")
    @PostMapping("/getConf")
    @LogAnnotation(module = "SuperConfigController", operation = "获得配置")
    @Permission(permission_code = PermissionCode.SUPER_MANAGE)
    public Result<GetDefaultConfVo> getConf() {
        GetDefaultConfVo result = configService.getDefaultConf();
        return Result.success(result);
    }

    @Transactional
    @Operation(summary = "修改配置")
    @ApiImplicitParam(dataType = "EditDefaultConfParam", name = "editDefaultConfParam", value = "修改配置", readOnly = true, required = true)
    @PostMapping("/editConf")
    @LogAnnotation(module = "SuperConfigController", operation = "修改配置")
    @Permission(permission_code = PermissionCode.SUPER_EDIT_DEFAULT_CONF,
            content = "修改全局默认基础数据配置")
    public Result editConf(@RequestBody @Valid EditDefaultConfParam editDefaultConfParam) {
        configService.editDefaultConf(
                editDefaultConfParam.getConf()
        );
        return Result.success(null);
    }

    @Transactional
    @Operation(summary = "获得默认功能权限配置")
    @PostMapping("/getDefaultFunctionPermission")
    @LogAnnotation(module = "SuperConfigController", operation = "获得默认功能权限配置")
    @Permission(permission_code = PermissionCode.SUPER_EDIT_DEFAULT_ROLE_FUNCTION)
    public Result<GetDefaultFunctionPermissionVo> getDefaultFunctionPermission() {
        GetDefaultFunctionPermissionVo result = configService.getDefaultFunctionPermission();
        return Result.success(result);
    }

    // @Transactional
    // @Operation(summary = "修改默认功能权限配置")
    // @ApiImplicitParam(dataType = "EditDefaultFunctionPermission", name = "editDefaultFunctionPermission", value = "修改默认功能权限配置", readOnly = true, required = true)
    // @PostMapping("/editDefaultFunctionPermission")
    // @LogAnnotation(module = "SuperConfigController", operation = "修改默认功能权限配置")
    // @Permission(permission_code = PermissionCode.SUPER_EDIT_DEFAULT_ROLE_FUNCTION)
    // public Result editDefaultFunctionPermission(@RequestBody @Valid EditDefaultFunctionPermission editDefaultFunctionPermission) {
    //     configService.editDefaultFunctionPermission(
    //             ParamUtil.parseId(editDefaultFunctionPermission.getAdminRoleId()),
    //             editDefaultFunctionPermission.getFunctionPermissionCodeList()
    //     );
    //     return Result.success(null);
    // }

}
